--! qt:dataset:src
set hive.fetch.task.conversion=more;
set hive.local.time.zone=UTC;

drop table timestamp_1;

create table timestamp_1 (t timestamp);
alter table timestamp_1 set serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe';

insert overwrite table timestamp_1
  select cast('2011-01-01 01:01:01' as timestamp) from src tablesample (1 rows);
select cast(t as boolean) from timestamp_1 limit 1;
select cast(t as tinyint) from timestamp_1 limit 1;
select cast(t as smallint) from timestamp_1 limit 1;
select cast(t as int) from timestamp_1 limit 1;
select cast(t as bigint) from timestamp_1 limit 1;
select cast(t as float) from timestamp_1 limit 1;
select cast(t as double) from timestamp_1 limit 1;
select cast(t as string) from timestamp_1 limit 1;

set hive.local.time.zone=Asia/Bangkok;

select cast(t as boolean) from timestamp_1 limit 1;
select cast(t as tinyint) from timestamp_1 limit 1;
select cast(t as smallint) from timestamp_1 limit 1;
select cast(t as int) from timestamp_1 limit 1;
select cast(t as bigint) from timestamp_1 limit 1;
select cast(t as float) from timestamp_1 limit 1;
select cast(t as double) from timestamp_1 limit 1;
select cast(t as string) from timestamp_1 limit 1;

set hive.local.time.zone=UTC;

insert overwrite table timestamp_1
  select '2011-01-01 01:01:01' from src tablesample (1 rows);
select cast(t as boolean) from timestamp_1 limit 1;
select cast(t as tinyint) from timestamp_1 limit 1;
select cast(t as smallint) from timestamp_1 limit 1;
select cast(t as int) from timestamp_1 limit 1;
select cast(t as bigint) from timestamp_1 limit 1;
select cast(t as float) from timestamp_1 limit 1;
select cast(t as double) from timestamp_1 limit 1;
select cast(t as string) from timestamp_1 limit 1;

insert overwrite table timestamp_1
  select '2011-01-01 01:01:01.1' from src tablesample (1 rows);
select cast(t as boolean) from timestamp_1 limit 1;
select cast(t as tinyint) from timestamp_1 limit 1;
select cast(t as smallint) from timestamp_1 limit 1;
select cast(t as int) from timestamp_1 limit 1;
select cast(t as bigint) from timestamp_1 limit 1;
select cast(t as float) from timestamp_1 limit 1;
select cast(t as double) from timestamp_1 limit 1;
select cast(t as string) from timestamp_1 limit 1;

insert overwrite table timestamp_1
  select '2011-01-01 01:01:01.0001' from src tablesample (1 rows);
select cast(t as boolean) from timestamp_1 limit 1;
select cast(t as tinyint) from timestamp_1 limit 1;
select cast(t as smallint) from timestamp_1 limit 1;
select cast(t as int) from timestamp_1 limit 1;
select cast(t as bigint) from timestamp_1 limit 1;
select cast(t as float) from timestamp_1 limit 1;
select cast(t as double) from timestamp_1 limit 1;
select cast(t as string) from timestamp_1 limit 1;

insert overwrite table timestamp_1
  select '2011-01-01 01:01:01.000100000' from src tablesample (1 rows);
select cast(t as boolean) from timestamp_1 limit 1;
select cast(t as tinyint) from timestamp_1 limit 1;
select cast(t as smallint) from timestamp_1 limit 1;
select cast(t as int) from timestamp_1 limit 1;
select cast(t as bigint) from timestamp_1 limit 1;
select cast(t as float) from timestamp_1 limit 1;
select cast(t as double) from timestamp_1 limit 1;
select cast(t as string) from timestamp_1 limit 1;

insert overwrite table timestamp_1
  select '2011-01-01 01:01:01.001000011' from src tablesample (1 rows);
select cast(t as boolean) from timestamp_1 limit 1;
select cast(t as tinyint) from timestamp_1 limit 1;
select cast(t as smallint) from timestamp_1 limit 1;
select cast(t as int) from timestamp_1 limit 1;
select cast(t as bigint) from timestamp_1 limit 1;
select cast(t as float) from timestamp_1 limit 1;
select cast(t as double) from timestamp_1 limit 1;
select cast(t as string) from timestamp_1 limit 1;


set hive.local.time.zone=LOCAL;
drop table timestamp_1;
